﻿using System.Collections.ObjectModel;
using System.Xml.Linq;
using System.ComponentModel;

namespace SharePointUtilitiesForDevelopers
{
    /// <summary>
    /// A domain class that represents a SharePoint content type.
    /// </summary>
    [ReadOnly(true)]
    [DefaultProperty("Name")]
    public class SharePointContentType
    {
        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>The id.</value>
        [Description("The id that identifies the content type.")]
        public string Id { get; set; }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        [Description("The content type name.")]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        /// <value>The description.</value>
        [Description("The content type description.")]
        public string Description { get; set; }

        /// <summary>
        /// Gets or sets the group.
        /// </summary>
        /// <value>The group.</value>
        [Description("The content type group.")]
        public string Group { get; set; }

        /// <summary>
        /// Gets or sets the fields.
        /// </summary>
        /// <value>The fields.</value>
        [Description("The list of fields in the content type.")]
        public ReadOnlyCollection<SharePointField> Fields { get; set; }

        /// <summary>
        /// Gets or sets the definition.
        /// </summary>
        /// <value>The definition.</value>
        [Description("The XML definition of the content type.")]
        public XElement Definition { get; set; }
        
        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="SharePointContentType"/> is sealed.
        /// </summary>
        /// <value><c>true</c> if sealed; otherwise, <c>false</c>.</value>
        [Description("Indicates if content types can inherit from this content type.")]
        public bool Sealed { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="SharePointContentType"/> is hidden.
        /// </summary>
        /// <value><c>true</c> if hidden; otherwise, <c>false</c>.</value>
        [Description("Indicates if the content type is hidden.")]
        public bool Hidden { get; set; }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return string.Format("{0} ({1})", Name, Id);
        }
    }
}